package com.kong.rabbitproducer;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author yukong
 * @date 2018/8/22
 * @description rabbitmq消费者 @RabbitListener(queues = "simpleMsg") 监听名simpleMsg的队列
 */
@Component
public class StringConsumer {

    @Resource
    private AmqpTemplate rabbitTemplate;

    /**
     * 消息消费
     * @RabbitHandler 代表此方法为接受到消息后的处理方法
     * 监听器监听指定的Queue
     */
    @RabbitListener(queues = "string")
    public void recieved(String msg) {
        System.out.println("消费者1: " + msg);
    }

    @RabbitListener(queues = "string")
    public void recieved1(String msg) {
        System.out.println("消费者2: " + msg);
    }
}